/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 2/10/14
 * Time: 7:37 AM
 * To change this template use File | Settings | File Templates.
 */
package com.societyGames.flashForms
{
import flash.events.Event;

//Stretches the item, not maintaining aspect ratio.
//Centers if the item has a weird origin.
public class ZeroOriginContainer extends SingleItemContainer
{
  private var _desiredWidth:Number;
  private var _desiredHeight:Number;

  public override function set width(value:Number):void
  {
    this._desiredWidth = value;
    recalculate();
  }

  public override function set height(value:Number):void
  {
    this._desiredHeight = value;
    recalculate();
  }

  protected override function childSizeChangedHandler(event:Event):void
  {
    recalculate();
  }

  private function recalculate():void
  {
    if (this._item != null)
    {
      this._item.width = _desiredWidth;
      this._item.height = _desiredHeight;

      this._item.x = _desiredWidth / 2;
      this._item.y = _desiredHeight / 2;
    }
  }
}
}
